package thread;

/**
 * Created with IntelliJ IDEA.
 * Description: wait/notify
 * User: 王圆豪
 * Date: 2025-04-27
 * Time: 23:53
 */
public class Demo24 {
    public static void main(String[] args) throws InterruptedException {
        Object locker1 = new Object();
        Thread t1 = new Thread(()->{
            synchronized (locker1) {
                try {
                    System.out.println("t1线程阻塞......");
                    locker1.wait();
                    System.out.println("t1唤醒成功！");
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });
        Thread t2 = new Thread(()->{
            synchronized (locker1) {
                System.out.println("通知t1线程就绪......");
                locker1.notify();
            }
        });
        t1.start();
        Thread.sleep(1);
        t2.start();
    }
}
